#include "self3dwindow.h"

Self3DWindow::Self3DWindow()
{

}

void Self3DWindow::mouseMoveEvent(QMouseEvent *event)
{
    //qDebug()<<"3D window mouse move";
//    if(event->buttons() & Qt::LeftButton)
    if(event->buttons().testFlag(Qt::LeftButton))
    {
        int tPosX = event->x();
        int tPosY = event->y();
        int tXOff = tPosX - mPressPosX;
        int tYOff = tPosY - mPressPosY;
//        if(tOffset)
//            qDebug()<<"Right Rotate,offset:"<<tOffset;
//        else
//            qDebug()<<"Left Rotate,offset:"<<tOffset;
        emit sigMouseDrag(tXOff,tYOff);
    }
}

void Self3DWindow::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        //qDebug()<<event->globalPos();   //获取鼠标指针的位置，相对屏幕的位置
        //qDebug()<<event->pos();         //获取鼠标指针在Self3DWindow窗口的位置
        mPressPosX = event->x();   //鼠标指针在Self3DWindow窗口的X
        mPressPosY = event->y();   //鼠标指针在Self3DWindow窗口的Y
        emit sigPosition(mPressPosX,mPressPosY);
    }
    event->ignore();
}

void Self3DWindow::wheelEvent(QWheelEvent *event)
{
    //qDebug()<<"Self3DWindow wheelEvent";
    if(event->delta() > 0) //滚轮远离使用者. 滚轮旋转一下默认15度
        emit sigZoom(1);   //1表示放大
    else                   //滚轮向使用者方向旋转
        emit sigZoom(-1);  //-1表示缩小
}
